package com.jing21.learn.fs.util;

import org.jglue.fluentjson.JsonBuilderFactory;
import org.springframework.stereotype.Component;

/**
 * Policy 生成工具
 * Create By zhengjing on 2017/11/8 09:20
 */
@Component
public class PolicyUtilly {

    public String read(String bucketName,String path){

        String osspath = bucketName + (path.startsWith("/") ? path : "/" + path);
        return JsonBuilderFactory.buildObject()
                .add("Version",1)
                .addArray("Statement")
                    .addObject()
                        .add("Effect","Allow")
                        .addArray("Action")
                            .add("oss:List*").add("oss:Get*").end()
                        .addArray("Resource")
                            .add("acs:oss:*:*:"+bucketName).add("acs:oss:*:*:"+ osspath).end()
                        .addObject("Condition")
                            .addObject("acs:CurrentTime")
                                .add("DateLessThan", "LocalDate").toString();

    }

    public static void main(String[] args) {

    }

}
